package com.syg.config;


import com.syg.Animal;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ServiceLoader;

/**
 * @author oe_shenyiguang
 * @date 2021年10月7日16:24:36
 * @version 1.0
 */
@Configuration
public class SpiConfiguration {

    @Bean
    public Animal animal(){
        Animal animal = null;

        ServiceLoader<Animal> animals = ServiceLoader.load(Animal.class);
        for (Animal value : animals) {
            animal = value;
            // 这里打破循环是因为只依赖一个jar,如果依赖多个jar会得到多个
            break;
        }

        return animal;
    }


    public static void main(String[] args) {
        ServiceLoader<Animal> animals = ServiceLoader.load(Animal.class);
        for (Animal value : animals) {
            System.out.println(value);
        }
    }
}
